import { Controller, Get, Post, Query, Req,Res, UseGuards,Response } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { AuthService } from "./auth.service";
import { GetCaptchaDto } from "./dto/get-captcha.dto";

export const jwtConstants = {
  secret: "secretKey"
};

@Controller("auth")
export class AuthController {
  constructor(
    private readonly authService: AuthService
  ) {
  }

  //进入路由前会进入拦截器
  @UseGuards(AuthGuard("local"))
  @Post("login")
  async login(@Req() req, @Res() res: Response) {
    //从请求头中取出账户对象进行登录
    return this.authService.login(req.user, res);
  }

  //获取注册的验证码
  @Get("getCaptcha")
  getCaptcha(@Query() dto: GetCaptchaDto, @Req() request) {
    return this.authService.getCaptcha(dto, request);
  }

}
